package com.wocao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wocao.entity.ZyBuilding;
import com.wocao.mapper.ZyBuildingMapper;
import com.wocao.service.ZyBuildingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wocao.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 楼栋  服务实现类
 *
 * @since 2023-11-29
 */
@Service
public class ZyBuildingServiceImpl extends ServiceImpl<ZyBuildingMapper, ZyBuilding> implements ZyBuildingService {

    @Autowired
    private ZyBuildingMapper zyBuildingMapper;

    @Override
    public Page<ZyBuilding> getBuildingsByLike(Page<ZyBuilding> zyBuildingPage, String buildingName, String buildingCode, String communityId) {
        return zyBuildingMapper.selectBuildingsByLike(zyBuildingPage, buildingName, buildingCode, communityId);
    }

    @Override
    public void export(HttpServletResponse response, String[] buildingIds) throws IOException {
        List<ZyBuilding> zyBuildings = new ArrayList<>();
        for (int i = 0; i < buildingIds.length; i++) {
            ZyBuilding zyBuilding = zyBuildingMapper.selectById(buildingIds[i]);
            zyBuildings.add(zyBuilding);
        }
        ExcelUtil.export(response, ZyBuilding.class, zyBuildings);
    }

    @Override
    public List<ZyBuilding> getBuildingsByComId(String communityId) {
        LambdaQueryWrapper<ZyBuilding> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ZyBuilding::getCommunityId, communityId);
        return zyBuildingMapper.selectList(queryWrapper);
    }

}
